package ppa.marc.importer.writer;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import ppa.marc.domain.Record;
import ppa.marc.importer.database.DataInsertionException;
import ppa.marc.importer.database.RecordInserter;

public class GenericRecordsInserter implements RecordsInserter {
	private final RecordInserter recordInserter;

	public GenericRecordsInserter(RecordInserter recordInserter) {
		this.recordInserter = recordInserter;
	}

	@Transactional // TODO add related configuration into xml to activate.
	@Override
	public void insertRecords(List<Record> records) {
		for(Record record : records) {
			try {
				recordInserter.insertRecord(record);
			} catch (DataInsertionException e) {
				throw new RuntimeException(e.getMessage());
			}
		}
	}
}
